package com.mrogrape.notepad.activity.action.item;

import java.awt.event.ActionEvent;
import java.util.List;

import javax.swing.Action;
import javax.swing.JCheckBoxMenuItem;

import com.mrogrape.notepad.activity.MainFrame;
import com.mrogrape.notepad.activity.action.NotepadAction;
import com.mrogrape.notepad.activity.entity.ViewSettings;
import com.mrogrape.notepad.data.ViewContext;
import com.mrogrape.notepad.resource.Settings;
import com.mrogrape.notepad.ui.editor.TextEditor;


public class HyperlinkMenuItemAction extends NotepadAction {

    /** serialVersionUID */
    private static final long serialVersionUID = -1L;

    public HyperlinkMenuItemAction(){

	super.putValue(Action.NAME, "Mark Hyperlinks");
	super.putValue(Action.SHORT_DESCRIPTION, "Toggle Mark Hyperlinks enabled.");
    }

    @Override
    public void actionPerformed(ActionEvent ae) {

	MainFrame frame = ViewContext.getMainFrame();
	JCheckBoxMenuItem item = (JCheckBoxMenuItem) ae.getSource();
	ViewSettings settings = Settings.getSettings().getViewSettings();

	boolean selected = item.isSelected();
	settings.setHyperlinksEnabled(selected);
	List<TextEditor> editors = frame.getAllTextEditors();
	for(TextEditor editor : editors){
	    editor.setHyperlinksEnabled(selected);
	}
    }
}
